<?php
/**
 * 同城微聚汇
 * ============================================================================
 * 版权所有 2015-2027 武汉鼎联信息技术有限公司，并保留所有权利。
 * 网站地址: http://dlshop.dliansoft.com
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 */
namespace app\admin\controller; 
use think\Controller;

class Kefu extends Base {
    
    public function index(){
      $admin_id = session('admin_id');
      $condtion='';
        if($admin_id!='admin'){
          $condtion['t0.admin_id']=$admin_id;
        }
        $service = M('service t0')->where($condtion)->field('t0.*,t1.admin_id,t1.user_name')->join('tp_admin t1','t0.admin_id=t1.admin_id','left')->select();
		    $this->assign('service',$service);
        $this->assign('admin_id',$admin_id);
        return $this->fetch();
    }
    
    /**
     * 添加修改编辑  短信模板
     */
    public function kefu_info(){
        
        $id = I('kf_id/d');
        $model = M("service");
        
        if(IS_POST)
        {    
            $data = I('post.');
            $data['add_time'] = time();
            if($id){
                $model->update($data);
            }else{
                $id = $model->save($data);
            }
            $this->success("操作成功!!!",U('Admin/Kefu/index'));
            exit;
        } 
         
        if($id){
            //进入编辑页面
            $kefu = $model->where("id" , $id)->find(); 
            $this->assign("kefu" , $kefu );
        }
         $admin = M('admin')->select();
         $this->assign('admin', $admin);
        return $this->fetch("kefu_info");
    }
    
    /**
     * 删除订单
     */
   public function del_kefu(){
       
       $model = M("service");
       $row = $model->where('id ='.$_GET['id'])->delete();
       $return_arr = array();
       if ($row){
           $return_arr = array('status' => 1,'msg' => '删除成功','data'  =>'',);   //$return_arr = array('status' => -1,'msg' => '删除失败','data'  =>'',);
       }else{
           $return_arr = array('status' => -1,'msg' => '删除失败','data'  =>'',);
       } 
       return $this->ajaxReturn($return_arr);
       
   }
   public function check_kf_no(){
      $kf_no=I('kf_no');
      $count=M('service')->where('kf_no',$kf_no)->count();
      return $count;
   }

}